import asyncio
import websockets

def logic(message):
    print("收到消息："+message)
    out = "你发送了内容:"+message
    print("回复消息："+out)
    #请自行补充逻辑
    return out

async def echo(websocket, path):
    async for message in websocket:
        out = logic(message)
        await websocket.send(out)

start_server = websockets.serve(echo, 'localhost', 8081)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()